home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / TextHarvest / TextHarvest-Install.exe / {app} / Help-ScanPosn.txt < prev    next >
Text File  |  2005-01-26  |  10KB  |  170 lines

  1. <h1>Parse-O-Matic: ScanPosn</h1>
  2.  
  3. <hl>Note: This is an appendix to the 'Parse-O-Matic Scripts' user manual.</hl>
  4.  
  5. <h2>Table of Contents</h2>
  6.  
  7. You can click on any section title below to jump directly to that section.
  8.  
  9.    <a href="#INTRODUC">Introduction</a>
  10.    <a href="#SCANLIST">The Scanlist</a>
  11.       <a href="#ACCVARIA">Accommodating Variation</a>
  12.       <a href="#PREFSUFF">Handling Prefixes and Suffixes</a>
  13.    <a href="#CONTROLS">Control Settings</a>
  14.       <a href="#FIRLASAN">Last, First and Any</a>
  15.       <a href="#BESTMATC">The "Best Match" Principle</a>
  16.    <a href="#REGULEXP">Regular Expressions (Finding Patterns)</a>
  17.  
  18. <a name="INTRODUC"><h2>Introduction</h2>
  19.  
  20. When you are analyzing data, a common requirement is to find out if one of several strings can be found in another string. For example, you might want to find out if a name starts with a 'salutation' (Mr., Mrs., Ms.). ScanPosn lets you perform such a search with a single command.
  21.  
  22. For example, to search for a salutation in a string:
  23. <hl>
  24.   ScanPosn from to MyVar '/Mr./Mrs./Miss/Ms.'
  25. </hl>
  26. If MyVar contains one of the scanterms (e.g. 'Mrs.') in the <a href="#SCANLIST">scanlist</a>, ScanPosn will set the appropriate "From" and "To" variables. Thus, if MyVar contains 'Ms. Mary Jones', the "From" variable is set to '1' and the "To" variable is set to '3' (since 'Ms.' goes from positions 1 to 3 in MyVar).
  27.  
  28. If none of the scanterms is found, the "From" variable is set to '0' and the special variable $Success is set to 'N'. Thus, if MyVar contains 'John Smith', no salutation is found, and the ScanPosn command shown above will set the "From" variable to '0'.
  29.  
  30. <a name="SCANLIST"><h2>The Scanlist</h2>
  31.  
  32. The scanlist can contain one or more scanterms. The <b>first</b> character in the scanlist is interpreted as the delimiter (separator) for the scanterms. Thus, the following scanlists are all valid:
  33. <hl>
  34.   '/Mr./Mrs./Miss/Ms.'                         <ùù Delimiter is: /
  35.   'xMr.xMrs.xMissxMs.'                         <ùù Delimiter is: x
  36.   '@Library@School@Gymnasium@Clinic/Hospital'  <ùù Delimiter is: @
  37.   '/Cow.'                                      <ùù Delimiter is: /
  38. </hl>
  39. The first example ('/Mr./Mrs./Miss/Ms.') has already been demonstrated. The second example uses the letter 'x' as a delimiter. This might be a bad choice for a delimiter; it would cause a problem if one of the scanterms contained an 'x', since it would be treated as <b>two</b> scanterms. For example:
  40. <hl>
  41.   'xJohnxTrixiexFred'
  42. </hl>
  43. The name 'Trixie' contains an 'x', so it would be broken down into two scanterms ('Tri' and 'ie'). You should always choose a scanlist delimiter that does not appear in the list of scanterms.
  44.  
  45. <a name="ACCVARIA"><h3>Accommodating Variation</h3>
  46.  
  47. When you design a scanlist, you should take into account the possibility that the input might contain strange variations. Consider this command:
  48. <hl>
  49.  ScanPosn x y 'Mr John Smith' '/Mr./Mrs./Ms.'
  50. </hl>
  51. This search will fail because the 'Mr' is followed by a space, not a period. A more forgiving command would be:
  52. <hl>
  53.  ScanPosn x y 'Mr John Smith' '/Mr./Mrs./Ms./Mr /Mrs /Ms '
  54. </hl>
  55. This would successfully locate the 'Mr ' string, and set x to '1' and y to '3'. (The '3' points to the space.)
  56.  
  57. <a name="PREFSUFF"><h3>Handling Prefixes and Suffixes</h3>
  58.  
  59. When designing a scanlist, you should consider that a scanterm might be part of a word. For example:
  60. <hl>
  61.   ScanPosn x y 'Mississipi Sue' '/Mr./Mrs./Miss/Ms.'
  62. </hl>
  63. This will find the 'Miss' in Mississippi, even though this is not part of a salutation. A more appropriate command would be:
  64. <hl>
  65.   ScanPosn x y 'Mississipi Sue' '/Mr./Mrs./Miss /Ms.'
  66. </hl>
  67. The space after 'Miss' in the scanlist ensures that if it is found, it will be separate from any word following it.
  68.  
  69. The trailing space is not necessary for the scanterm 'Mr.', since no word contains a period. However, if you do include spaces after the periods (as in '/Mr. /Mrs. /Miss /Ms. ') the consistency of rationale may simplify your subsequent script code.
  70.  
  71. You must also take suffixes into account. For example:
  72. <hl>
  73.   ScanPosn x y 'Zinc Enterprises' '/Inc/Co/Enterprises'
  74. </hl>
  75. This will find the 'inc' in 'Zinc'. You can add a space in front of each scanterm to ensure that it is separated from any other word:
  76. <hl>
  77.   ScanPosn x y 'Zinc Enterprises' '/ Inc/ Co/ Enterprises'
  78. </hl>
  79. You may be tempted to always put spaces on both sides of a word, to handle both prefixes and suffixes. However, consider this example:
  80. <hl>
  81.   ScanPosn x y 'Wazoo Inc' '/ Inc / Co / Enterprises '
  82. </hl>
  83. None of the scanterms is found, because the 'Inc' in the source string does not end in a space. The control settings (described next) can help you address this kind of problem.
  84.  
  85. <a name="CONTROLS"><h2>Control Settings</h2>
  86.  
  87. Unless otherwise instructed, ScanPosn will find the first scanterm that appears anywhere in the source string, and return its start and end positions. It will also ignore text case (e.g. 'CAT' = 'Cat'). You can modify this behavior by using the optional control setting.
  88.  
  89. <a name="FIRLASAN"><h3>Last, First and Any</h3>
  90.  
  91. The 'Last' (i.e. rightmost) control setting tells ScanPosn to find the scanterm that has the highest "To" value with the lowest "From" value. This means that <b>all</b> of the scanterms are evaluated. Consider this command:
  92. <hl>
  93.   ScanPosn x y 'SHREWxxxCATxxxMOUSExxx' '/CAT/DOGGY/MOUSE/ELK' 'Last'
  94. </hl>
  95. ScanPosn finds 'CAT', but continues looking to see if there are any better matches to the right. Eventually it finds MOUSE and sets x to '15' and y to '19' (pointing at 'MOUSE').
  96.  
  97. If you use the 'First' (i.e. leftmost) parameter, ScanPosn will check all the scanterms to find out which one has the lowest "From" position with the highest "To" value. For example:
  98. <hl>
  99.   ScanPosn x y 'SHREWxxxCATxxxMOUSExxx' '/CAT/DOGGY/MOUSE/ELK' 'First'
  100. </hl>
  101. This will set x to '9' and y to '11' (pointing at 'CAT').
  102.  
  103. If you do not specify 'First' or 'Last', ScanPosn assumes you mean to use the 'Any' control setting. It finds the first scanterm it can, and ignores the rest.
  104. <hl>
  105.   ScanPosn x y 'SHREWxxxCATxxxMOUSExxx' '/CAT/DOGGY/MOUSE/ELK'
  106. </hl>
  107. The first scanterm is 'CAT', and this can be found at positions 9 to 11. ScanPosn will return those values, and ignore the rest of the scanterms.
  108.  
  109. The 'Any' technique is useful if you want to know if one of the scanterms appears in the source string, but you are not interested in finding out which one.  (You can specify 'Any' explicitly, but since it is the default control setting, this is not necessary.)
  110.  
  111. <a name="BESTMATC"><h3>The "Best Match" Principle</h3>
  112.  
  113. Note: The "Best Match" principle does not apply to the 'Any' control setting. It applies only to 'First' and 'Last' searches.
  114.  
  115. To use the ScanPosn command effectively, you must understand the concept of 'the best match'. This can be illustrated with an example:
  116. <hl>
  117.   ScanPosn x y 'MegaWhizco International' '/CO/WHIZCO/MEGAWHIZ' 'Last'
  118. </hl>
  119. The ScanPosn command finds the scanterm 'CO' at positions 5 to 6. However, it continues looking for an even better match.
  120.  
  121. It finds that 'WHIZCO' is just as far to the right (i.e. it ends at position 6), but has a lower starting position. This makes it a better match.
  122.  
  123. The next scanterm ('MEGAWHIZ') has a lower starting position, but its ending position is not as good for a 'Last' search because it is not as far to the right.
  124.  
  125. As a result of all this, ScanPosn will set x to '5' and y to '10' ù pointing to the "From" and "To" columns for 'WHIZCO'.
  126.  
  127. In other words, when ScanPosn is looking for the 'Last' scanterm, it will first identify the found scanterms which have the highest ending position, and then choose the longest one.
  128.  
  129. Here is an example using a 'First' search:
  130. <hl>
  131.   ScanPosn x y 'Our catalog is enclosed' '/CAT/MOOSE/CATALOG/DOG' 'First'
  132. </hl>
  133. ScanPosn finds 'CAT' at positions 5 to 7, but as it continues checking the scanterms, it finds that 'CATALOG' is just as far to the left (i.e. it starts at position 5), but it is a better match since it has a higher ending position.
  134.  
  135. As a result, ScanPosn will set x to '5' and y to '11'.
  136.  
  137. The "Best Match" principle does not affect 'Any' searches. For example:
  138. <hl>
  139.   ScanPosn x y 'Our catalog is enclosed' '/CAT/MOOSE/CATALOG/DOG'
  140. </hl>
  141. This sets x to '5' and y to '7'. Since this is a 'Any' search, ScanPosn stops looking as soon as it has found a match.
  142.  
  143. When doing an 'Any' search, you cannot be sure if any of the other scan terms appear in the source string. For example:
  144. <hl>
  145.   ScanPosn x y 'Our cat and dog are upstairs' '/CAT/DOG'
  146. </hl>
  147. This will find 'CAT' and stop looking for additional matches. If you change the order of the scanlist, you will get <b>different</b> values:
  148. <hl>
  149.   ScanPosn x y 'Our cat and dog are upstairs' '/DOG/CAT'
  150. </hl>
  151. This would give different values for the "From" and "To" variables. This is normal behavior; an 'Any' search is useful only for detecting if one of the scanterms appears in the source string. After doing an 'Any' search, you will typically check the special variable $Success to see if a string was found.
  152.  
  153. <a name="REGULEXP"><h2>Regular Expressions (Finding Patterns)</h2>
  154.  
  155. You can include the control setting "RegExp" to indicate that ScanPosn should look for a <b>pattern</b> of characters rather than specific characters.  For example:
  156. <hl>
  157.   ; Scale   ----+----1----+----
  158.   Source = 'Kitty Cats Are Cool'
  159.   ScanList = '/c.t/co*l'
  160.   ScanPosn p1 p2 Source ScanList 'First RegExp'
  161.   ScanPosn p3 p4 Source ScanList 'Last RegExp'
  162. </hl>
  163. This would set the following values:
  164. <hl>
  165.   p1 =  7
  166.   p2 =  9
  167.   p3 = 16
  168.   p4 = 19
  169. </hl>
  170. For an explanation of regular expressions, click <a href="pommel://Help-RegExp.txt">here</a>.